import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);//vue的插件机制
//Vuex.Store 构造器选项
// 固化vuex
const curStore = store => {
	uni.getStorage({
		key: 'state',
		success: function(res) {
			let locState = JSON.parse(res)
			store.replaceState(locState)
		}
	});
	store.subscribe((mutation, state) => {
		uni.setStorage({
			key: 'state',
			data: JSON.stringify(state),
			success: function() {
				console.log('success');
			}
		});
	})
}
const store = new Vuex.Store({
	state:{//存放状态
		token:"",
	},
	mutations: {
		setToken(state, token) {
			state.token = token
		}
	},
	plugins: [curStore]
})
export default store